/*
 *  Cero Project - Copyright   2006 The Cero Developement Team 
 *  (Michael Laguerre, Camille Roux, Matthieu Segret, Mathieu Sivade) 
 * 
 *  This program is free software; you can redistribute it and/or modify it 
 *  under the terms of the GNU General Public License as published by the Free 
 *  Software Foundation; either version 2 of the License, or (at your option) 
 *  any later version.
 * 
 *  This program is distributed in the hope that it will be useful, but 
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 *  for more details.
 */

package org.ceroproject.plugin;

import org.ceroproject.games.Game;
import org.ceroproject.ui.InterfaceModule;
import org.ceroproject.ui.UserInterface;

class InterfaceModulePlugin extends AbstractPlugin implements Plugin {

	private Class<? extends InterfaceModule> moduleType;

	private InterfaceModule dumbInstance;

	public InterfaceModulePlugin(Class<? extends InterfaceModule> moduleClass)
			throws NotInstantiableException {
		moduleType = moduleClass;
		dumbInstance = (InterfaceModule) tryInstanciante(moduleType);
	}

	public String getPluginName() {
		return dumbInstance.getInterfaceModuleName();
	}

	public InterfaceModule newModuleInstance() {
		try {
			return (InterfaceModule) tryInstanciante(moduleType);
		} catch (NotInstantiableException e) {
			// the class has been instanciated one already, there shouldn't be
			// any problem instanciating it again
			e.printStackTrace();
		}
		return null;
	}

	Class<? extends InterfaceModule> getModuleType() {
		return moduleType;
	}

	Class<? extends Game> getGameType() {
		return dumbInstance.appliesToGame();
	}

	Class<? extends UserInterface> getInterfaceType() {
		return dumbInstance.appliesToInterface();
	}
}
